package com.solcoo.merchant.ui.menu;

import java.util.ArrayList;
import java.util.List;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.GridView;

import com.android.common.util.DialogUtil;
import com.solcoo.merchant.ApplicationExt;
import com.solcoo.merchant.R;
import com.solcoo.merchant.base.BaseActivity;
import com.solcoo.merchant.model.Menu;
import com.solcoo.merchant.model.Version;
import com.solcoo.merchant.ui.exp.ExpActivity;
import com.solcoo.merchant.ui.level.LevelActivity;
import com.solcoo.merchant.ui.member.MemberActivity;
import com.solcoo.merchant.ui.order.OrderActivity;
import com.solcoo.merchant.ui.pay.PayActivity;
import com.solcoo.merchant.ui.recharge.RechargeActivity;
import com.solcoo.merchant.ui.setting.SettingActivity;

public class MenuActivity extends BaseActivity {

	private GridView menu;

	private Dialog outDialog;// 退出确认

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);

		outDialog = DialogUtil.createDialog(this, onConfirmQuitClickListener,
				DialogUtil.onNegativeListener, null, "确定退出系统？", null);
		menu = (GridView) findViewById(R.id.grid_menu);
		menu.setAdapter(new MenuAdapter(this, getMenuList()));
	}

	@Override
	protected void onResume() {
		super.onResume();
		Version.showDialog();
		findViewById(R.id.btn_go_back).setVisibility(View.INVISIBLE);
	}

	private List<Menu> getMenuList() {
		List<Menu> result = new ArrayList<Menu>();
		result.add(new Menu(R.drawable.menu_pay, "支付", PayActivity.class));
		result.add(new Menu(R.drawable.menu_recharge, "充值",
				RechargeActivity.class));
		result.add(new Menu(R.drawable.menu_member, "会员", MemberActivity.class));
		result.add(new Menu(R.drawable.menu_order, "对账表", OrderActivity.class));
		result.add(new Menu(R.drawable.menu_discount, "折扣设置",
				LevelActivity.class));
		result.add(new Menu(R.drawable.menu_setting, "账户设置",
				SettingActivity.class));
		result.add(new Menu(R.drawable.menu_exp, "经验值", ExpActivity.class));
		return result;
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			outDialog.show();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	}

	public static DialogInterface.OnClickListener onConfirmQuitClickListener = new DialogInterface.OnClickListener() {
		@Override
		public void onClick(DialogInterface dialog, int which) {
			dialog.dismiss();
			ApplicationExt.destory();
		}
	};
}
